package com.twohand.admin.Controller;

import com.twohand.admin.Annotation.Permission;
import com.twohand.admin.Dto.BatchChangeMoneyDto;
import com.twohand.admin.Dto.OrderListQueryDto;
import com.twohand.admin.Dto.QrcodeListQueryDto;
import com.twohand.admin.Entity.Order;
import com.twohand.admin.Entity.Qrcode;
import com.twohand.admin.Service.BillService;
import com.twohand.admin.Service.OrderService;
import com.twohand.admin.Util.ExcelReader;
import com.twohand.admin.Util.PageResponse;
import com.twohand.admin.Vo.Order.OrderStatisVo;
import com.twohand.admin.Vo.SelectOptions;
import org.apache.poi.ss.usermodel.PictureData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    OrderService orderService;
    @Autowired
    BillService billService;
    @Autowired
    ExcelReader excelReader;
    @Permission(value = "order:list")
    @GetMapping
    PageResponse<Order> getAllSales(OrderListQueryDto orderListQueryDto){
        return orderService.orderList(orderListQueryDto);
    }
    @Permission(value = "order:add")
    @PostMapping
    Boolean addSales(@RequestBody Order order){
        return orderService.addOrder(order);
    }
    @Permission(value = "order:edit")
    @PutMapping
    Boolean changeSales(@RequestBody Order order){
        return orderService.changeOrder(order);
    }
    @Permission(value = "order:delete")
    @DeleteMapping("/{id}")
    Boolean delSales(@PathVariable Integer id){
        return  orderService.delOrder(id);
    }
    @GetMapping("/bill")
    List<SelectOptions> getOptions(){
        return billService.getOptions();
    }
    @PostMapping("/batch/add")
    Object batchAdd(@RequestBody List<Order> orderList){
        return orderService.BatchAddOrder(orderList);
    }

    @Permission(value = "order:import")
    @PostMapping("/import/add")
    Boolean importOrder(@RequestBody Order order){
        return orderService.addOrder(order);
    }

    @Permission(value = "order:import2")
    @PostMapping("/import2/add")
    Boolean importOrder2(@RequestBody Order order){
        return orderService.importOrder2(order);
    }
    @PostMapping("/parseImage")
    Map<String,List<String>> parseImage(@RequestBody MultipartFile file, String type) throws IOException {
        excelReader.setTypePath(type);
        return excelReader.read(file);
    }

    @Permission("billbatch:changeMoney")
    @PostMapping("/batchChangeMoney")
    Boolean batchChangeMoney(@RequestBody BatchChangeMoneyDto batchChangeMoneyDto){
        return orderService.batchChangeMoney(batchChangeMoneyDto);
    }

    @Permission("billbatch:changeBillNo")
    @PostMapping("/batchChangeBid")
    Boolean batchChangeBid(@RequestBody BatchChangeMoneyDto batchChangeMoneyDto){
        return orderService.batchChangeBid(batchChangeMoneyDto);
    }

}
